package servlet;

import bean.Help;
import com.alibaba.fastjson.JSON;
import service.HelpService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/helpServlet")
public class HelpServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");// 设置请求参数的编码格式
        response.setContentType("text/html;charset=utf-8");// 设置网页界面相应的代码
        HelpService helpService = new HelpService();
        List<Help> list = helpService.selectAll();
        //5将结果返回给对应的界面
        String str = JSON.toJSONString(list);//将集合转为json字符串
        response.getWriter().write(str);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
